Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egjs/component

Package Overview
Dependencies
Maintainers
8
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egjs/component

A base class utility that manages events and options in modules.

  • 2.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
123K
increased by6.92%
Maintainers
8
Weekly downloads
 
Created

What is @egjs/component?

@egjs/component is a simple and lightweight JavaScript library for creating and managing custom events. It allows developers to create components that can emit and listen to events, making it easier to build interactive and modular applications.

What are @egjs/component's main functionalities?

Creating a Component

This code demonstrates how to create a new component by extending the Component class from @egjs/component. The new component can then be instantiated and used in your application.

const Component = require('@egjs/component');

class MyComponent extends Component {
  constructor() {
    super();
  }
}

const myComponent = new MyComponent();

Emitting Events

This code demonstrates how to emit custom events from a component. The `doSomething` method triggers an event called 'somethingHappened' with some data. The event listener logs the data to the console when the event is triggered.

const Component = require('@egjs/component');

class MyComponent extends Component {
  constructor() {
    super();
  }

  doSomething() {
    this.trigger('somethingHappened', { data: 'example data' });
  }
}

const myComponent = new MyComponent();
myComponent.on('somethingHappened', (event) => {
  console.log(event.data); // Output: example data
});
myComponent.doSomething();

Listening to Events

This code demonstrates how to listen to custom events in a component. The `on` method is used to register an event listener for 'customEvent'. When the event is triggered, the listener logs the event data to the console.

const Component = require('@egjs/component');

class MyComponent extends Component {
  constructor() {
    super();
  }
}

const myComponent = new MyComponent();
myComponent.on('customEvent', (event) => {
  console.log('Custom event received:', event);
});

myComponent.trigger('customEvent', { message: 'Hello, world!' });

Other packages similar to @egjs/component

FAQs

Package last updated on 22 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc